package com.ff.neuropp.repository;

import com.ff.neuropp.domain.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

public interface OrderRepository extends JpaRepository<Order, Integer> {


    public Order findByOrderStatusAndCourse_Id(Integer status,Integer courseId);

    public Order findByOrderNum(String orderId);

    public List<Order> findAllByCourse_idAndOrderStatus(Integer id, Integer i);

    public List<Order> findAllByUserIdAndOrderStatus(String userId,Integer status);

    /**
     * 通讯录
     */
    @Query(value = "SELECT aa.user_id AS contactId,tus.user_name as contactName ,c.apply_status AS appStatus,c.status,c.reason " +
            "FROM t_order a INNER JOIN t_order aa ON a.course_id = aa.course_id " +
            "LEFT JOIN t_contacts c ON a.user_id = c.user_id " +
            " INNER JOIN t_ios_user tus on  tus.user_id=aa.user_id " +
            "WHERE a.user_id = ?1 " +
            "AND a.user_id != aa.user_id  and a.order_status=1 ",nativeQuery = true)
    public List<Map<String,Object>> contacts(String userId);
    
    /**
     * 判断当前人 当前课程是否购买过
     * @param userId
     * @param courseId
     * @return
     */
	public Order findByUserIdAndCourse_id(String userId, Integer courseId);


	/**
	 * 我购买的课程信息
	 * @param userId
	 * @return
	 */
	public List<Order> findByOrderStatusAndUserId(int i, String userId);

}
